/**
 * Copyright (c) Chris Myers 2007
 * May 21, 2007
 */
package com.chrisandjo.rostra.dao.jpa;

import com.chrisandjo.rostra.dao.PersonDao;
import com.chrisandjo.rostra.domain.Person;
import com.chrisandjo.rostra.domain.PersonEntity;
import org.springframework.orm.jpa.support.JpaDaoSupport;

import java.util.HashSet;
import java.util.Set;

/**
 * @author Chris
 */
public class PersonDaoImpl extends JpaDaoSupport implements PersonDao {
    public static final String PERSON_ENTITY = "PersonEntity";

    public final void save(Person person) {
        getJpaTemplate().persist(person);
    }

    public final Person getPersonById(long id) {
        return getJpaTemplate().find(PersonEntity.class, id);
    }

    @SuppressWarnings({"unchecked"})
    public Set<Person> getPeople() {
        return new HashSet<Person>(
                getJpaTemplate().find("select p from " +
                        PERSON_ENTITY +
                        " p"));
    }

}
